﻿
@{
    ViewData["Title"] = "UserIndex";
    Layout = "~/Views/Share/_LayoutBody.cshtml";
}

<div class="list-wall">
    <div class="list-top">
        <div class="layui-btn-group">
            <form class="layui-form">
                <div class="layui-form-item" style="margin-bottom:5px">
                    <div class="layui-input-inline" style="width:100px">
                        <select id="StrSearchType" name="query" lay-verify="required">
                            <option value="0">商品名称</option>
                            <option value="1">通用名</option>
                            <option value="2">生产厂家</option>
                            <option value="3">所属分类</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" id="StrSearch" name="title" required lay-verify="required"  autocomplete="off" class="layui-input" style="width:200px;">
                    </div>
                    <div class="layui-input-inline" style="padding-left:10px">
                        <button type="button" authorize="yes" class="layui-btn layui-btn-xs layui-btn-normal" data-type="Search" id="Search"><i class="layui-icon ">&#xe615;</i> 查询</button>
                    </div>
                </div>
            </form>
        </div>                
        <div class="layui-btn-group" style="float:right">
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Add" id="Add"><i class="layui-icon">&#xe61f;</i> 新增</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Edit" id="Edit"><i class="layui-icon">&#xe642;</i> 修改</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Del" id="Del"><i class="layui-icon ">&#xe640;</i> 删除</button>
            <button type="button" authorize="yes" class="layui-btn layui-btn-xs" data-type="Excel" id="Excel"><i class="layui-icon ">&#xe601;</i> 导出</button>
        </div>

    </div>
    <div class="gridPanel">
        <table id="list1" class="table table-condensed"></table>
        <div id="pager1"></div>
    </div>
</div>
<script>$('.list-top').authorizeButton()</script>
<script>
    var CX_StrSearch = "";
    var bodyheight = 0;
      $(function () {
        bodyheight = document.body.scrollHeight;
        $("#list1").jqGrid({
            styleUI: 'Bootstrap',
            url: '@Url.Action("GoodsInfoList")',
            datatype: "json",
            jsonReader: {
                repeatitems: false
            },
            colModel: [
                { label: 'id', name: 'id', index: 'id', key: true, width: 75, hidden: true},
                { label: '商品编号', name: 'GoodID', index: 'GoodID', width: 100, align: 'center'},
                { label: '商品名称', name: 'GoodName', index: 'GoodName', width: 100, align: 'center' },
                { label: '通用名', name: 'TYName', index: 'TYName', width: 100, align: 'center' },
                { label: '拼音码', name: 'PYM', index: 'PYM', width: 80, align: 'center'},
                { label: '条形码', name: 'TXM', index: 'TXM', width: 140, align: 'center' },
                { label: '单位', name: 'DW', index: 'DW', width: 100, align: 'center' },
                { label: '规格', name: 'GGType', index: 'GGType', width: 100, align: 'center' },
                { label: '型号', name: 'ModelType', index: 'ModelType', width: 100, align: 'center' },
                { label: '生产厂家', name: 'SCCJ', index: 'SCCJ', width: 100, align: 'center' },
                { label: '许可证', name: 'XKZ', index: 'XKZ', width: 100, align: 'center' },
                { label: '类别', name: 'ClassID', index: 'ClassID', width: 100, align: 'center' },
                { label: '所属分类', name: 'ForType', index: 'ForType', width: 100, align: 'center' },
                { label: '零售价', name: 'ShopPrice', index: 'ShopPrice', width: 100, align: 'center' },
                { label: '备注', name: 'BZ', index: 'BZ', width: 100, align: 'center' },
                { label: '创建日期', name: 'CreateDate', index: 'CreateDate', width: 100, align: 'center' },
                { label: '创建人', name: 'CreateName', index: 'CreateName', width: 100, align: 'center' },
                { label: '修改日期', name: 'EditDate', index: 'EditDate', width: 100, align: 'center' },
                { label: '修改人', name: 'EditName', index: 'EditName', width: 100, align: 'center' }
            ],
            width: "99%",
            autowidth: true,
            height: $(window).height()-110,
            rowNum: 30,//一页显示多少条
            rowList: [10,20,30,50,100],//可供用户选择一页显示多少条
            pager: '#pager1',//表格页脚的占位符(一般是div)的id
            sortname: 'id',//初始化的时候排序的字段
            sortorder: "desc",//排序方式,可选desc,asc
            mtype: "post",//向后台请求数据的ajax的类型。可选post,get
            viewrecords: true,
            shrinkToFit: false,
            rownumbers: true,
          });
          $(window).bind('resize', function () {
              $("#list1").setGridWidth($(window).width() - 20);
              $("#list1").setGridHeight($(window).height() - 110);
          }).trigger('resize');

    });
    $(function () {
        layui.use('form', function () {
            var form = layui.form;
            $('#StrSearchType').val(0);
            form.render();
        });
    });

    $(function (){
        $.hands = {
            Add: function () {
                $.FromOpen('GoodsFromAdd', '新增商品', '/GoodsInfo/AddIndex', '600px', '420px', '1000');
            },
            Edit: function () {
                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                var url = "/GoodsInfo/EditIndex" + "?ids=" + ids;
                $.FromOpen('GoodsFromEdit', '修改商品', url, '600px', '420px', '1000');

            },
            Del: function () {
                var id = $("#list1").jqGrid('getGridParam', 'selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
                var rowData = $("#list1").jqGrid("getRowData", id);//根据上面的id获得本行的所有数据
                var ids = rowData.id; //获得制定列的值 （UserID 为colModel的name）
                if (ids == null || ids == undefined) {
                    layer.msg("请选择一行", { icon: 2 });
                    return;
                }
                layer.confirm('确认要删除选择的数据吗？', {
                    title: "删除商品",
                    btn: ['确定', '关闭'] //按钮
                }, function (index, layero) {
                    $.loading(true, "正在删除数据");
                    window.setTimeout(function () {
                        $.ajax({
                            url: "/GoodsInfo/DeleteGoods/",
                            data: { ids: ids },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                $.loading(false);
                                if (data.errorMsg) {
                                    layer.msg(data.errorMsg, { icon: 2 });
                                }
                                else {
                                    $("#list1").trigger("reloadGrid");

                                }
                            },
                            error: function () {
                                $.loading(false);

                            },
                            complete: function () {
                                $.loading(false);
                            }
                        });

                    }, 500);
                    layer.close(index);

                }, function () {
                    return true;
                });
            },
            Search: function () {
                $.loading(true, "正在查询数据");
                CX_StrSearchType = $('#StrSearchType').val();
                CX_StrSearch = $('#StrSearch').val();
                window.setTimeout(function () {
                    $("#list1").jqGrid('setGridParam', {
                        datatype: 'json',
                        postData: { 'StrSearchType': CX_StrSearchType, 'StrSearch': CX_StrSearch },
                        //page: 1
                    }).trigger("reloadGrid");

                    $.loading(false);
                }, 500);
            },
            Excel: function () {
                $.loading(true, "正在提交数据");
                window.setTimeout(function () {
                    var funFrom = document.createElement("form");
                    document.body.appendChild(funFrom);
                    funFrom.action = '/GoodsInfo/GetFile/';
                    funFrom.method = 'post';

                    var total = $("#list1").jqGrid('getGridParam', 'records');
                    if (parseInt(total) > 0) {
                        var newStrSearchType = document.createElement("input");
                        newStrSearchType.setAttribute("name", "StrSearchType");
                        newStrSearchType.setAttribute("type", "hidden");
                        newStrSearchType.setAttribute("value", CX_StrSearchType);

                        var newStrSearch = document.createElement("input");
                        newStrSearch.setAttribute("name", "StrSearch");
                        newStrSearch.setAttribute("type", "hidden");
                        newStrSearch.setAttribute("value", CX_StrSearch);

                        funFrom.appendChild(newStrSearchType);
                        funFrom.appendChild(newStrSearch);
                        funFrom.submit();
                    } else {
                        top.layer.msg("空数据导出失败", { icon: 2 });
                    }

                }, 500);
                $.loading(false);
            },
            init:function() {
                $('#Add').on('click', $.hands.Add);
                $('#Edit').on('click', $.hands.Edit);
                $('#Del').on('click', $.hands.Del);
                $('#Search').on('click', $.hands.Search);
                $('#Excel').on('click', $.hands.Excel);
            }
        }
        $(function () {
            $.hands.init();
        });
    });



</script>


